<template>
  <div class="user-center">
    <!-- <div class="header">
      <div class="header-left">
        <div class="back" @click="handleReturn">
          <i class="i-left-white"></i>
        </div>
      </div>
      <div class="header-middle"></div>
      <div class="header-right"></div>
    </div> -->
    <div class="content">
      <div class="user-info">
        <div class="avatar">
          <img :src="avatar" :onerror="errorImg"/>
        </div>
        <div class="info">
          <div>{{nickname}}</div>
          <div class="m-t-12">{{phone}}</div>
        </div>
      </div>
      <ul class="list">
        <li class="list-item">
          <div class="list-item__panel border-r">
            <div class="list-item__panel__text">万能账户</div>
            <div class="list-item__panel__num">{{commission}}</div>
          </div>
          <div class="list-item__panel border-r">
            <div class="list-item__panel__text">元宝</div>
            <div class="list-item__panel__num">{{balance}}</div>
          </div>
          <div class="list-item__panel">
            <div class="list-item__panel__text">钻石</div>
            <div class="list-item__panel__num">{{jewelry}}</div>
          </div>
        </li>
        <li class="list-item">
          <div class="list-item__panel border-r">
            <div class="list-item__panel__text">天使股</div>
            <div class="list-item__panel__num">{{classAngel}}</div>
          </div>
          <div class="list-item__panel border-r">
            <div class="list-item__panel__text">BCL锁仓</div>
            <div class="list-item__panel__num">{{lockBcl}}</div>
          </div>
          <div class="list-item__panel">
            <div class="list-item__panel__text">BCL释放总数</div>
            <div class="list-item__panel__num">{{bcl}}</div>
          </div>
        </li>
        <li class="list-item">
          <div class="list-item__panel border-r" @click="handleOrder">
            <i class="i-order"></i>
            <div class="list-item__panel__num">我的订单</div>
          </div>
          <div class="list-item__panel" @click="handleAddress">
            <i class="i-addr"></i>
            <div class="list-item__panel__num">我的地址</div>
          </div>
          <div class="list-item__panel"></div>
        </li>
      </ul>
      <ul class="action-list">
        <li class="action-list-item">
          <div class="action-list-item__left">
            <i class="i-phone"></i>
            <div  class="m-l-8">绑定手机</div>
          </div>
          <i class="i-right"></i>
        </li>
        <li class="action-list-item">
          <div class="action-list-item__left">
            <i class="i-earn"></i>
            <div class="m-l-8">分享赚钱</div>
          </div>
          <i class="i-right"></i>
        </li>
        <!-- <li class="action-list-item">
          <div class="action-list-item__left">
            <i class="i-record"></i>
            <div class="m-l-8">邀请记录</div>
          </div>
          <i class="i-right"></i>
        </li> -->
        <li class="action-list-item" @click="handleAddress"> 
          <div class="action-list-item__left">
            <i class="i-address"></i>
            <div class="m-l-8">收货地址</div>
          </div>
          <i class="i-right"></i>
        </li>
      </ul>
    </div>
    <footerbar></footerbar>
  </div>
</template>

<script>
import wx from "weixin-js-sdk";
import { getUserInfo, getUserMoney } from "@/api/bdchats"
import footerbar from "@/components/footerbar"  

export default {
  components: {footerbar},
  data() {
    return {
      avatar: '',
      errorImg: 'this.src="https://images.bdchats.com/prod/upload/default-user.png"',
      nickname: '',
      phone: '',
      commission: '',
      balance: 0,
      jewelry:'',
      classAngel: '',
      bcl: 0,
      lockBcl: 0
    };
  },
  created() {
    this.getUser()
    this.getAssets();
    this.$store.commit('SET_ACTIVE', 2)
  },
  methods: {
    getUser() {
      getUserInfo().then(response=>{
        if(response.data) { 
          this.avatar = process.env.VUE_APP_AVATAR_URL + (response.data.userId % 10000) + '/' + response.data.userId + '.jpg'
          this.phone = response.data.phone
          this.nickname = response.data.nickname
        }

      })
    },
    getAssets() {
      getUserMoney().then(response=>{
        if(response.data) {
          this.commission = Math.floor(response.data.commission * 100) / 100 
          this.balance =  Math.floor(response.data.balance * 100) / 100 
          this.jewelry = response.data.jewels 
          this.classAngel = response.data.classAngel
          this.bcl = Math.floor(response.data.bcl  * 100) / 100 
          this.lockBcl = Math.floor(response.data.lockedBcl * 100) / 100 
        }
      })
    },
    handleReturn() {
      this.$router.go(-1);
    },
    imageShow(src) {
      const img = {};
      img.loading = require("@/assets/images/loading.gif");
      img.src = src;
      return img;
    },
    imgError(item) {
      item.img = 'https://images.bdchats.com/prod/upload/default-user.png'
    },
    getUserInfo() {},
    handleOrder() {
      this.$router.push("/user/orderlist")
    },
    handleAddress() {
      this.$router.push("/address/list")
    }
  }
};
</script>
